package phantri.uit.menunhahang;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MenuActivity extends Activity {
	Button btn_monan;
	Button btn_douong;
	Button btn_dachon;
	Button btn_ykien;
	Button btn_vechtrinh;
	Button btn_thoat;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);
		btn_monan = (Button) findViewById(R.id.btn_monan);
		btn_douong = (Button) findViewById(R.id.btn_douong);
		btn_dachon = (Button) findViewById(R.id.btn_dachon);
		btn_ykien = (Button) findViewById(R.id.btn_ykien);
		btn_vechtrinh = (Button) findViewById(R.id.btn_vechtrinh);
		btn_thoat = (Button) findViewById(R.id.btn_thoat);
		btn_monan.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent int_monan = new Intent(getApplicationContext(),
						MonanActivity.class);
				startActivity(int_monan);
			}
		});

		btn_douong.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent int_douong = new Intent(MenuActivity.this,
						DouongActivity.class);
				startActivity(int_douong);
			}
		});

		btn_dachon.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent int_dachon = new Intent(MenuActivity.this,
						DachonActivity.class);
				startActivity(int_dachon);
			}
		});

		btn_ykien.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent int_ykien = new Intent(MenuActivity.this,
						YkienActivity.class);
				startActivity(int_ykien);
			}
		});

		btn_thoat.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				showDialog(0);
			}
		});
		btn_vechtrinh.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				showDialog(1);

			}
		});

	}

	@Override
	protected Dialog onCreateDialog(int id) {
		Dialog d = null;
		switch (id) {
		case 0:
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage("Bạn có chắc muốn thoát ?")
					.setCancelable(false)
					.setPositiveButton("Có",
							new DialogInterface.OnClickListener() {

								public void onClick(DialogInterface dialog,
										int which) {
									// TODO Viết sự kiện khi ấn nút yes sẽ thoát
									// ứng dụng
									MenuActivity.this.finish();
								}
							})
					.setNegativeButton("Không",
							new DialogInterface.OnClickListener() {

								public void onClick(DialogInterface dialog,
										int which) {
									// TODO Viết sự kiện khi ấn nút No sẽ thoát
									// hội thoại Dialog này
									dialog.cancel();
								}
							});
			d = builder.create();
			break;
		case 1:
			AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
			builder1.setMessage(R.string.dialog_vechtrinh)
					.setCancelable(false)
					.setNegativeButton("OK",
							new DialogInterface.OnClickListener() {

								public void onClick(DialogInterface dialog,
										int which) {
									dialog.cancel();
								}
							});
			d = builder1.create();
			break;
		default:
			d = null;
			break;
		}
		return d;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}
}
